﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Text;
using System.IO;

namespace FrontCenter.Expand
{
    public static class RechargeHelper
    {
        private const string m_contentType = "application/x-www-form-urlencoded;charset=utf-8";

        #region Public

        public static string Distribute(string source, string mothed, string paramters)
        {
            string content = string.Empty;
            HttpWebRequest request = HttpWebRequest.Create(source) as HttpWebRequest;
            request.Method = mothed;
            request.ContentType = m_contentType;
            using (Stream _stream = request.GetRequestStream())
            {
                _stream.Write(Encoding.UTF8.GetBytes(paramters), 0, Encoding.UTF8.GetByteCount(paramters));
                _stream.Flush();
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                content = reader.ReadToEnd();
                            }
                        }
                    }
                }
            }
            return content;
        }

        #endregion Public

    }
}